/*菜单拼接*/
var leftMenu={
    /*主菜单*/
    getMenus : function () {
        var data=eval('(' + $(sessionStorage)[0].user +')');
        var menuHtml="";
            //菜单
        if(data.menuList.length>0){
            //一级菜单
            menuHtml=$.trim(menuHtml);
            for(var i=0;i<data.menuList.length;i++){
                var dataTargetId="#model"+data.menuList[i].id;
                if(data.menuList[i].menuList.length>0){
                    menuHtml += '<li>' +
                        '<a href="javascript:void(0);" data-toggle="collapse" data-target="'+dataTargetId+'">' +
                        '<div class="pull-left"><i class="zmdi '+data.menuList[i].menuIcon+'"></i>' +
                        '<span class="right-nav-text">'+data.menuList[i].menuName+'</span>' +
                        '</div>' +
                        '<div class="pull-right">' +
                        '<span class="label label-success">'+data.menuList[i].menuList.length+'</span>' +
                        '</div><div class="clearfix"></div>' +
                        '</a>' +
                        '<ul id="model'+data.menuList[i].id+'" class="collapse collapse-level-1">';
                    //二级菜单
                    for(var j=0;j<data.menuList[i].menuList.length;j++){
                        menuHtml+= '<li onclick="leftMenu.setClass(this,&quot;S&quot;,&quot;'+data.menuList[i].menuList[j].menuUrl+'&quot;,&quot;'+data.menuList[i].menuList[j].id+'&quot;)">' +
                            '<a href="javascript:void(0);">'+
                            '<i class="zmdi '+data.menuList[i].menuList[j].menuIcon+'"></i>' +
                            '<i style="margin-left: 20px;">'+data.menuList[i].menuList[j].menuName+'</i>'+
                            '</a>' +
                            '</li>';
                    }
                    menuHtml+='</ul></li>';
                }else{
                    menuHtml +='<li onclick="leftMenu.setClass(&quot;'+dataTargetId+'&quot;,&quot;F&quot;,&quot;'+data.menuList[i].menuUrl+'&quot;,&quot;'+data.menuList[i].id+'&quot;)">'+
                        '<a href="javascript:void(0);" id="model'+data.menuList[i].id+'">' +
                        '<div class="pull-left"><i class="zmdi '+data.menuList[i].menuIcon+'"></i>' +
                        '<span class="right-nav-text">'+data.menuList[i].menuName+'</span>' +
                        '</div>' +
                        '<div class="pull-right">' +
                        '<span class="label label-success"></span>' +
                        '</div><div class="clearfix"></div></a></li>';
                }
            }
        }
        $(".img-circle").attr('src',data.photo);
        $(".bg-transparent").html(data.loginName);
        $("#menus").after(menuHtml);
    },
    setClass: function (uu,isLevel,menuUrl,menuId) {
        if('S' == isLevel){
            $("#leftMenus").find("a").removeClass("active");
            $(uu).parent().prev().addClass("active");
        }else {
            $("#leftMenus").find("a").removeClass("active");
            $(uu).addClass("active");
        }
        loadUtil = new Load($);
        loadUtil.load({
            container:'#homeContent',
            url: application.contextPath+menuUrl+"?menuId="+menuId
        });
    }
};

$(document).ready(function(){
    leftMenu.getMenus();
});